#ifndef MLOADER_COMMON
#define MLOADER_COMMON

#include <ctime>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include "GMath.hpp"

/**
 * maximum path length
 * http://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html
 */
#ifndef PATH_MAX
#   define PATH_MAX 4096
#endif

#if defined( _MSC_VER ) || defined( __MINGW32__ )
#	define REAL_PATH(in, out) ::_fullpath((out), (in), PATH_MAX)
#	define LOCAL_TIME(a, b) localtime_s((b), (a))
#else
#	define REAL_PATH(in, out) ::realpath((in), (out));
#	define LOCAL_TIME(a, b) localtime_r((a), (b))  
#endif


#define ML_DEBUG 1

#if ML_DEBUG
#   include <assert.h>
#   include <cstdio>
#   define ML_ASSERT(expression) assert(expression)
#   define ML_LOG(format, ...)                                                                    \
{                                                                                                 \
    time_t t = time(0);                                                                           \
    struct tm ptm;                                                                                \
    memset(&ptm, 0, sizeof(ptm));                                                                 \
    LOCAL_TIME(&t, &ptm);																          \
    fprintf(stdout, "[ INFO ] [ %4d-%02d-%02d %02d:%02d:%02d ] [ %s:%s:%d ] \n" format "\n\n",    \
            ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, ptm.tm_sec, \
            __FILE__, __FUNCTION__ , __LINE__ , ##__VA_ARGS__);                                   \
}
#else
#   define ML_ASSERT(expression)
#   define ML_LOG(format, ...)
#endif

namespace MLoader {
    
    typedef enum Flag {
        Success,
        Fail,
        OutOfMemory,
    } Flag;

}

#endif // MLOADER_COMMON
